/********************************************************************/
/*                                                                  */
/*	       CREAM: A (JVM-like) Toy Abstract Machine             */
/*                                                                  */
/*		Copyright (c) 1998- , C.R. Ramakrishnan             */
/*                                                                  */
/*  $Id: memory.h,v 1.2 2012/04/26 18:23:59 cram Exp $ */
/*                                                                  */
/********************************************************************/

#ifndef Memory_Included
#define Memory_Included

/****************************************************************************/
/*** sizes of various memory areas ***/

#define STACKSIZE 262144
#define HEAPSIZE 262144
               /* 256K each of stack and heap must be sufficient */
#define STATICSIZE 32768
               /* 32K for static data structures will be sufficient for now */
               /* when we start adding libraries, we'll have to revisit this */



/****************************************************************************/
/*** Q. What type is a memory word?   ***/
/*** A. An unsigned, 32-bit quantity. ***/

typedef unsigned long int MemoryElement;

MemoryElement stack[STACKSIZE];
MemoryElement heap[HEAPSIZE];
MemoryElement static_area[STATICSIZE];

/****************************************************************************/
/*** Various AM registers ***/

unsigned int sp; /* Stack pointer: always points to one element above
		    the top element in the stack. Also represents top
		    of operand stack (except briefly during environment
		    build/tear-downs). */

unsigned int bp; /* Base pointer; called in JVM description as
		    "vars" pointer; basically, always points to the
		    0th argument of the current method. */

unsigned int ep; /* Environment pointer: points to the most recent
		    execution environment */

unsigned int hp; /* Heap pointer; again points to one element above the
		    top element of the heap. Used only for allocation. */


void init_memory();  /* actually, initializes only the memory registers */

/****************************************************************************/
/* Compiler interface: Class Tables (indices of classes into static areas)  */

#define MAXCLASSES 128
               /* Can we really cope with more than 128 classes at a time?  */
int region_table[MAXCLASSES];


/****************************************************************************/
/* Convenience (for compiler's use only; not part of Cream instruction set) */

float i2f(MemoryElement);
MemoryElement f2i(float);

#endif
